package com.bmslz.monitor.helper;

import com.bmslz.monitor.base.factory.AlarmNotifyFactory;
import com.bmslz.monitor.base.dto.DoAlarmDto;
import com.bmslz.monitor.base.entity.AlarmModel;
import com.bmslz.monitor.service.AlarmNotify;
import com.bmslz.monitor.service.IAlarmModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class AlarmNotifyHelper {

    @Autowired
    private AlarmNotifyFactory alarmNotifyFactory;
    @Autowired
    private IAlarmModelService alarmModelService;

    public void sendNotify(List<DoAlarmDto> doAlarmDtoList) {
        for (DoAlarmDto doAlarmDto : doAlarmDtoList) {
            AlarmModel alarmModel = alarmModelService.getById(doAlarmDto.getAlarmModelRule().getAlarmModelId());
            String notifyType = alarmModel.getNotifyType();//推送类型
            AlarmNotify alarmNotifyUtil = alarmNotifyFactory.getStrategy(notifyType);//获取告警推送具体实现
            alarmNotifyUtil.send(doAlarmDto, alarmModel);//推送告警数据
        }
    }
}
